﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace Expression.Samples.Physics.Behaviors
{

	public abstract class PhysicsBehavior<T> : Behavior<T> where T : FrameworkElement
	{
		

		public PhysicsBehavior() {
		}

		private void TryGetContext() {
			PhysicsContext context = PhysicsContext.FindContext(this.AssociatedObject);
			if (context == null) {
				context = new PhysicsContext();
				PhysicsContext.SetPhysicsContext(Application.Current.RootVisual, context);
			}

			this.Context = context;
		}

		private PhysicsContext context = null;
		private PhysicsContext Context {
			get { return this.context; }
			set {
				this.context = value;
			}
		}

		protected Simulator Simulator {
			get {

				if (this.Context == null) {
					this.TryGetContext();
				}
				return this.Context.Simulator;
			}
		}


		
	}
}
